/*!
 *@file main.qml
 *@brief 主文件
 *@version 1.0
 *@section LICENSE Copyright (C) 2003-2103 CamelSoft Corporation
 *@author zhengtianzuo
*/
import QtQuick 2.7
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.0
import QtQuick.Window 2.2

ApplicationWindow {
    id: frmWindow
    visible: true
    width: 400;
    height: 600;
    title: qsTr("Qml底部导航")
    property var dpi: Screen.pixelDensity / (96 / 25.4);
    property var hHeight: 1
    //顶部状态栏颜色
    property var hColor: "#fff";
    //获取状态栏高度
    property var hPadding: Screen.height - Screen.desktopAvailableHeight;

    footer: TabBar {
        id: bar
        height: dp(35);
        width: parent.width
        currentIndex: 0
        ListModel {
            id: myModel
            ListElement { modelText: "首页";icon: "\uf015";}
            ListElement { modelText: "发现"; icon: "\uf14e";}
            ListElement { modelText: "消息";icon:"\uf27a";}
            ListElement { modelText: "我的";icon:"\uf2c0"}
        }
        Repeater {
            model: myModel
            TabButton {
                height: bar.height
                contentItem:Text{
                    text: modelText
                    horizontalAlignment: Text.AlignHCenter
                    verticalAlignment: Text.AlignBottom
                    color: (model.index === bar.currentIndex) ? "#f74c4c" : "#000000";

                }
                background:Text{
                    font.family: "FontAwesome";
                    font.pixelSize: dp(15);
                    horizontalAlignment: Text.AlignHCenter
                    topPadding: dp(3);
                    color: (model.index === bar.currentIndex) ? "#f74c4c" : "#909090";
                    text:icon;
                }
            }

        }
    }
    SwipeView {
        id: view
        height: frmWindow.height - bar.height
        width: parent.width
        currentIndex: bar.currentIndex
        interactive: false;
        Rectangle{
            Loader{
                active:true;
                source: "page_home_1.qml";
            }
        }
        Rectangle{
            Text {
                text: qsTr("发现")
                anchors.centerIn: parent
            }
        }
        Rectangle{
            Loader{
                active:true;
                source: "page_home_messag.qml";
            }
        }
        Rectangle{
            Text {
                text: qsTr("我的")
                anchors.centerIn: parent
            }
        }

    }
    Rectangle
    {
        anchors.top: bar.top
        width: parent.width;
        height: dp(1);
        color: "#eeeeee";
        z:2;
    }
    function dp(val)
    {
        //处理屏幕dpi
       if(Qt.platform.os==='windows')
       {
//        return dpi*val*1.5;
       }
       return dpi*val;
    }
    StackView
    {
        id:stack;
        anchors.fill: parent
        initialItem: view;
    }

}
